import android.R
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.ImageView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity

class ImageViewActivity(iTest: Int) : AppCompatActivity() {
    private val buttonPrevious = findViewById<View>(R.id.button_previous) as Button
    private val buttonNext = findViewById<View>(R.id.buttonview_input) as Button
    private val imageViewFunny = findViewById<View>(R.id.image_view_funny) as ImageView
    private val imageIDArray = intArrayOf(
        R.drawable.funny_1, R.drawable.funny_2,
        R.drawable.funny_3, R.drawable.funny_4, R.drawable.funny_5,
        R.drawable.funny_6
    )
    private var imageIDArrayCurrentIndex = 0


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        this.enableEdgeToEdge()
        setContentView(R.layout.activity_image_view)

        /*ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });*/
        buttonPrevious.setOnClickListener(MyButtonClickListener())
        buttonNext.setOnClickListener(MyButtonClickListener())
    }

    private inner class MyButtonClickListener : View.OnClickListener {
        override fun onClick(view: View) {
            if ((view as Button).text === "下一个") {
                imageIDArrayCurrentIndex++
            } else {
                imageIDArrayCurrentIndex--
            }
            imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex])
        }
    }
}